/**
 * 
 */
package com.agilegroup.crm.ui.actions;

import java.text.DateFormatSymbols;
import java.util.Calendar;

import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;

/**
 * @author hisham
 *
 */
public class DateTimeDialog {

	private int hour;
	private int minute;
	private int year;
	private int month;
	private int day;
	private TextView textView;
	private TextView textday;
	
	public DateTimeDialog(TextView textView,TextView textday) {
		this.textView=textView;
		this.textday=textday;
	}
	public  TimePickerDialog.OnTimeSetListener timePickerListener = new TimePickerDialog.OnTimeSetListener() {
		public void onTimeSet(TimePicker view, int selectedHour,int selectedMinute) {
			hour = selectedHour;
			minute = selectedMinute;
			textView.setText(new StringBuilder().append(pad(hour)).append(":").append(pad(minute))); 
		}
	};
 
	private static String pad(int c) {
		if (c >= 10)return String.valueOf(c);
		else return "0" + String.valueOf(c);
	}
	
	public DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {
		public void onDateSet(DatePicker view, int selectedYear,int selectedMonth, int selectedDay) {
		year = selectedYear;
		month = selectedMonth;
		day = selectedDay;
		textView.setText(new StringBuilder().append(day).append("/").append(month + 1).append("/").append(year).append(" "));
		if(textday!=null){
			  String dayNames[] = new DateFormatSymbols().getWeekdays();
			  Calendar date1 = Calendar.getInstance();
			  date1.set(year, month, day);
			  textday.setText(dayNames[date1.get(Calendar.DAY_OF_WEEK)]);
		}
		}
	};
}
